package com.zyg.manager.controller;

import com.zyg.common.utils.FastDFSClient;
import com.zyg.common.utils.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 功能：
 * 作者： fufeixiang
 * 日期： 2021-12-02
 */
@RestController
@RequestMapping("/manager")
public class FileController {

    @PostMapping("/upload")
    public R upload(MultipartFile file) throws Exception {
        FastDFSClient fastDFSClient = new FastDFSClient("classpath:fastdfs.conf");
        //获取文件名
        String originalFilename = file.getOriginalFilename();
        //获取后缀名
        String extr = originalFilename.substring(originalFilename.lastIndexOf(".")+1);
        //上传文件
        String s = fastDFSClient.uploadFile(file.getBytes(), extr);
        //获取文件路径
        String url = "http://192.168.35.132:8888/"+s;
        return R.ok().put("url",url);
    }
}
